<%@ page language="java" contentType="text/html;charset=UTF-8"
   	pageEncoding="UTF-8"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="JavaScript">
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
				function Validate()
				  {
					 /*var image =document.getElementById("image").value;
					 if(image!=''){
						  var checkimg = image.toLowerCase();
						  if (!checkimg.match(/(\.jpg|\.png|\.JPG|\.PNG|\.jpeg|\.JPEG)$/)){
							  alert("Please enter  Image  File Extensions .jpg,.png,.jpeg");
							  document.getElementById("image").focus();
							  return false;
						    }
						 }
					 return true;*/
					 
					 var file=document.getElementById("txtfile").value;
					 var title=document.getElementById("txttitle").value;
					 if(trim(file)==""){
						 alert("Please choose file to upload");
						 return false;
					 }
					 if(trim(title)==""){
						 alert("Please enter title");
						 document.getElementById("txttitle").focus();
						 return false;
					 }
					 return true;
				 }	
				
</script>
</head>
<% 
	String title=(request.getParameter("title")==null?"":URLDecoder.decode(request.getParameter("title"), "UTF-8"));
	String desc=(request.getParameter("description")==null?"":URLDecoder.decode(request.getParameter("description"), "UTF-8"));
	String keywords=(request.getParameter("keywords")==null?"":URLDecoder.decode(request.getParameter("keywords"), "UTF-8"));
	String sizeErr="";
	if(title!="" || desc!=""){
		sizeErr="The file you choose to upload is too big, please try again.";
	}
%>
<body>
<form:form modelAttribute="uploadItem" name="frm" method="post" enctype="multipart/form-data" onsubmit="return Validate();">
<table cellpadding="0" cellspacing="0" width="730" align="center" border="0">
		
	<tr align="center"><td colspan="2" style="color: #333; font-size: 13px;" height="30"><u>Upload ឯកសារ</u></td></tr>
	<tr><td colspan="2"></td></tr>
	<tr><td colspan="2" height="10"> </td></tr>
	<tr>
		<td width="150" valign="top" height="30" align="right" style="padding-top: 4px;" class="mylabel">* ជ្រើសរើស file :&nbsp;</td>	
		<td width="" align="left"><form:input path="fileData" id="txtfile" type="file" /><br><span style="font-size: 9px; color: #666;">ទំហំធំបំផុត: 1.5 GB</span></td>
	</tr>
	
	<tr>
		<td height="30" align="right" class="mylabel">* ចំណងជើង :&nbsp;</td>	
		<td align="left"><input type="text" id="txttitle" name="txttitle" maxlength="255" value="<%=title%>" style="width: 400px;" class="box"/></td>
	</tr>
	<tr>
		<td height="30" align="right" class="mylabel">* ប្រភេទ :&nbsp;</td>
		<td align="left">
			<select name="txtcat" style="height:20px; width: 405px;">
				<c:forEach var="i" begin="0" end="${fn:length(categories)-1}" step="1" varStatus ="status">
					<c:choose>
						<c:when test="${category==categories[i].CATEGORY_ID}">
							<option selected="selected" value="${categories[i].CATEGORY_ID}"><c:out value="${categories[i].CATEGORY_NAME}"/></option>			
						</c:when>
						<c:otherwise>
							<option value="${categories[i].CATEGORY_ID}"><c:out value="${categories[i].CATEGORY_NAME}"/></option>			
						</c:otherwise>
					</c:choose>
					
				
				</c:forEach>
			</select>
		</td>
	</tr>
	<tr><td colspan="2" height="3"> </td></tr>
	<tr>
		<td align="right" class="mylabel">បរិយាយ :&nbsp;</td>	
		<td align="left"><textarea name="txtdesc" rows="10" style="font-family: verdana, sans-serif;font-size:11px;width: 400px;"><%=desc%></textarea></td>
	</tr>
	<tr><td colspan="2" height="8"> </td></tr>
	<tr>
		<td height="30" valign="top" align="right" style="padding-top: 4px; " class="mylabel">ពាក្យគន្លឹះ :&nbsp;</td>	
		<td align="left"><input type="text" id="txtkeyword" value="<%=keywords%>" name="txtkeyword" maxlength="255" style="width: 400px;" class="box"/>
		<br><span style="font-size: 9px; color: #666; ">ឧទាហរណ៍. Business Administration ; Financial Management</span>
		</td>
	</tr>
	<tr><td colspan="2" height="10"> </td></tr>
	<tr>
		<td height="5"></td>
		<td height="5" align="left" class="mylabel">* សំរាប់ព័ត៌មានចំបាច់ត្រូវបញ្ចូល</td>
	</tr>
	<tr><td colspan="2" height="8"> </td></tr>
	<tr>
		<td height="5"></td>
		<td height="5" align="left" style="color: red; font-size: 11px;"><%=sizeErr%></td>
	</tr>
	<tr><td colspan="2" height="5"> </td></tr>
	<tr>
		<td colspan="2" align="center" height="30"><input type="submit"​ class="input_button" value="រក្សាទុក">&nbsp;&nbsp;<input type="button" class="input_button" onclick='window.location="myuploads.html"' value="បោះបង់"></td>
	</tr>
	<tr><td colspan="2" height="25">&nbsp;</td></tr>
</table>
</form:form>
</body>
</html>